<?php
/**
 * ������ ��� ������ � ������������ �������������
 * 
 * @author Mazvv
 * @package LoginManager
 *	
 */
class Login_model extends Model {
	
	public function __construct() {
		parent::Model(); 
		$this->db->query('set names \'utf8\'');
	}
	
	public function CheckUser($p_userLogin, $p_userPassword) {
		$today = date("Y-m-d");
		$this->db->select('_users.rid as usersRID, _users.edate_passwd, _users.chdate_passwd, 
							_employeers.f_name, _employeers.s_name, _employeers.l_name,
							_filials.rid as filialsRID, _positions.rid as positionsRID, _positions.name, MAX(_emp_to_positions_rows.bdate) as positionDATEFROM');
		$this->db->from('_users');
		$this->db->join('_employeers', '_employeers.rid = _users._employeers_rid AND _employeers.archive = 0');
		$this->db->join('_filials', '_filials.rid = _employeers._filials_rid AND _filials.archive = 0');
		$this->db->join('_emp_to_positions_rows', '_employeers.rid = _emp_to_positions_rows._employeers_rid AND _emp_to_positions_rows.archive = 0');		
		$this->db->join('_positions', '_positions.rid = _emp_to_positions_rows._positions_rid AND _positions.archive = 0');
		$this->db->where(array('_users.user_login'=>$p_userLogin, '_users.user_passwd'=>(empty($p_userPassword))?'':md5($p_userPassword), '_users.archive'=>0, '_emp_to_positions_rows.bdate<='=>$today));
		$this->db->groupby('_users.rid');
		$query = $this->db->get();
		if($query->num_rows()){ 
			return $query->row();
		}
		return False;
	}
}
?>